function cal(a, b, c, d) {
  return a + b * c - d;
}

const newCal = curry(cal, 1, 2);

function curry(fn, ...args) {
  return function bar(...rest) {
    const allArgs = [...args, ...rest];
    if (allArgs.length >= fn.length) {
      // 参数够了
      return fn(...allArgs);
    } else {
      // 参数不够
      return curry(fn, ...allArgs);
    }
  };
}

console.log(cal(1, 2, 3, 4));
console.log(cal(1, 2, 3, 5));
console.log(cal(1, 2, 5, 6));
console.log(cal(1, 2, 7, 8));
